package com.tidy.seed.admin.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tidy.seed.admin.system.entity.Role;
import com.tidy.seed.admin.system.service.RoleService;
import com.tidy.seed.common.Result;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

import org.springframework.web.bind.annotation.RestController;
        
// ✅ Swagger 引入
import io.swagger.annotations.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author HZ-ZY
 * @since 2025-08-05
 */
@RestController
@Api(tags = "Role 接口")
@RequestMapping("/admin/system/role")
        public class RoleController {
    
@Resource
private RoleService roleService;

@ApiOperation(value = "新增或更新Role")
@PostMapping
public Result save(@RequestBody @ApiParam("Role 对象") Role role) {
    roleService.saveOrUpdate(role);
        return Result.success();
        }

@ApiOperation(value = "根据 ID 删除Role")
@DeleteMapping("/{id}")
public Result delete(@PathVariable @ApiParam("ID") Integer id) {
    roleService.removeById(id);
        return Result.success();
        }

@ApiOperation(value = "批量删除Role")
@PostMapping("/del/batch")
public Result deleteBatch(@RequestBody @ApiParam("ID 列表") List<Integer> ids) {
    roleService.removeByIds(ids);
        return Result.success();
        }

@ApiOperation(value = "查询全部Role")
@GetMapping
public Result findAll() {
        return Result.success(roleService.list());
        }

@ApiOperation(value = "根据 ID 查询Role")
@GetMapping("/{id}")
public Result findOneById(@PathVariable @ApiParam("ID") Integer id) {
        return Result.success(roleService.getById(id));
        }

@ApiOperation(value = "分页查询Role")
@GetMapping("/page")
public Result findPage(@RequestParam @ApiParam("页码") Integer pageNum,
@RequestParam @ApiParam("页大小") Integer pageSize) {
        QueryWrapper<Role> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("id");
        return Result.success(roleService.page(new Page<>(pageNum, pageSize), queryWrapper));
        }

        }
